# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  
@software: PyCharm 
@file: class_classmethod.py 
@time: 2019/6/25 12:35
"""

'''
类方法的一个主要用途就是定义多个构造器
'''
import time

class Date:
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day

    # alternate constructor
    @classmethod
    def today(cls):
        t = time.localtime()
        return cls(t.tm_year, t.tm_mon, t.tm_mday)


# Example use
a = Date(2019, 6, 25)
b = Date.today()
print(a.year, a.month, a.day)
print(b.year, b.month, b.day)